<%@page import="tu.java.login.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
    <%
    boolean isload = true;
    if( request.getMethod().equals("POST"))
    {
    	String login = request.getParameter("login");
    	if(login!=null && login.equals("yes")){
	    	User user = (User) session.getAttribute("userObj");
	    	user.setEmail(request.getParameter("email"));
	    	user.setPassword(request.getParameter("hp"));	
	    	if( user.Login(request) ){
	    		response.sendRedirect(request.getContextPath());
	    	}
	    	else{
	    		user = new User();
	    		isload = false;
	    	}
    	} 
    }
    if(isload){    	
    %>    
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/sha512.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/js/forms.js"></script> 
    <div id="content">
		  <div id="login-box" class="login-popup">
        <a href="<%=request.getRequestURI()%>" class="close"><img src="<%=request.getContextPath()%>/img/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>
          <form method="post" id="loginForm" name="loginform" class="signin" action="<%=request.getContextPath()%>/login/login.jsp">
                <input type="hidden" name="login" value="">
                <fieldset class="textbox" id="textbox">
            	<label class="email">
                <span>Е-поща:</span>
                <input id="email" name="email" value="" type="text" autocomplete="on" placeholder="Е-поща" onblur="validateEmail(this.form.email)">
                </label>
                
                <label class="password">
                <span>Парола</span>
                <input id="password" name="password" value="" type="password" placeholder="Парола" onblur="validatePassword(this.form.password)">
                </label>
                
                <button class="button" type="button" onclick="javascript:document.forms.loginform.login.value='yes'; formhash(this.form, this.form.password);">Вход</button>
                
                <p>
                	<a class="forgot" href="#">Забравена парола?</a>
                </p>
                <p id="error"></p>
                </fieldset>
          </form>
		</div>
		</div>
		<% }
		else{%>
		<script type="text/javascript">		
		alert("Невалиден е-мейл или парола");
		window.location.href='<%=request.getContextPath()%>';
		</script>
		<% }%>